<template>
  <div class="bg-white rounded-lg p-5 h-full">
    <div class="font-bold text-lg mb-4">消毒器械设备管理管理</div>

    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-row :gutter="15">
        <el-form-item prop="enterpriseName">
          <el-input
            v-model="queryParams.enterpriseName"
            placeholder="请输入机构名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>

        <el-form-item prop="lightScrubStatus">
          <el-select
            v-model="queryParams.lightScrubStatus"
            placeholder="紫外线灯擦拭状态"
          >
            <el-option
              v-for="dict in dict.type.disinfect_device_operate_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="lightMonitorStatus">
          <el-select
            v-model="queryParams.lightMonitorStatus"
            placeholder="紫外线灯强度监测状态"
          >
            <el-option
              v-for="dict in dict.type.disinfect_device_operate_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="disinfectMachineStatus">
          <el-select
            v-model="queryParams.disinfectMachineStatus"
            placeholder="空气消毒机消毒效果监测状态"
          >
            <el-option
              v-for="dict in dict.type.disinfect_device_operate_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="lightDisinStatus">
          <el-select
            v-model="queryParams.lightDisinStatus"
            placeholder="紫外线灯消毒状态"
          >
            <el-option
              v-for="dict in dict.type.disinfect_device_operate_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-row>
    </el-form>
    <div>
      <el-button type="primary" @click="search">搜索</el-button>
      <el-button @click="reset">重置</el-button>
    </div>

    <el-table
      class="mt-4"
      v-loading="loading"
      :data="dataList"
      border
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="index" width="55" align="center" label="序号" />
      <el-table-column
        label="医疗机构名称"
        align="center"
        prop="enterpriseName"
      />
      <el-table-column
        label="灯管擦拭状态"
        align="center"
        prop="lightScrubStatus"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.disinfect_device_operate_status"
            :value="scope.row.lightScrubStatus"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="紫外线灯强度监测状态"
        align="center"
        prop="lightMonitorStatus"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.disinfect_device_operate_status"
            :value="scope.row.lightMonitorStatus"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="空气消毒机消毒效果监测状态"
        align="center"
        prop="disinfectMachineStatus"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.disinfect_device_operate_status"
            :value="scope.row.disinfectMachineStatus"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="紫外线灯消毒状态"
        align="center"
        prop="lightDisinStatus"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.disinfect_device_operate_status"
            :value="scope.row.lightDisinStatus"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="300"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="toRecordPage(scope.row, 0)"
            >紫外线灯擦拭记录</el-button
          >
          <el-button size="mini" type="text" @click="toRecordPage(scope.row, 1)"
            >紫外线灯强度监测记录</el-button
          >
          <el-button size="mini" type="text" @click="toRecordPage(scope.row, 2)"
            >空气消毒机消毒效果监测记录</el-button
          >
          <el-button size="mini" type="text" @click="toRecordPage(scope.row, 3)"
            >紫外线灯消毒记录</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getDataList"
    />
  </div>
</template>

<script>

import { getDeviceManageListAPI } from "@/api/zhangping/health-care/device-manage";


export default {
  name: "Info",
  dicts: ["disinfect_device_operate_status"],
 
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 一企一档表格数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        enterpriseName: null,
        lightScrubStatus: null,
        lightDisinStatus: null,
        lightMonitorStatus: null,
        disinfectMachineStatus: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      detailForm: {},
      isEdit: false,
      editVisible: false,
    
    };
  },
  created() {
    this.loading = false;
    this.getDataList();
  
  },
  methods: {
    toRecordPage(row, type) {
      const pathMap = {
        0: "ur-rub",
        1: "ur-strength",
        2: "air-disinfect",
        3: "ur-disinfect",
      };
      const obj = {
        path: `/health-care/equipment-manage/${pathMap[type]}`,
        query: {
          id: "111",
          type: type,
        },
      };
      this.$router.push(obj);
    },
    /** 查询表格列表 */
    getDataList() {
      this.loading = true;
      getDeviceManageListAPI(this.queryParams)
        .then((response) => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.$refs.queryForm.resetFields();
      this.search();
    },
    /** 搜索按钮操作 */
    search() {
      this.queryParams.pageNum = 1;
      this.getDataList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.detailForm = {};
      this.isEdit = false;
      this.editVisible = true;
    },
    /** 修改按钮操作 */
    handleUpdate(row, type) {
      // this.reset();
      const id = row.id || this.ids;
      getInfo(id).then((response) => {
        this.detailForm = response.data;
        if (type == 1) {
          this.isEdit = true;
        } else {
          // 查看
          this.isEdit = false;
        }
        this.editVisible = true;
      });
    },
    /** 提交按钮 */
    submitForm(form, id) {
      if (id != null) {
        updateInfo(form).then((response) => {
          this.$modal.msgSuccess("修改成功");
          this.editVisible = false;
          this.getDataList();
        });
      } else {
        addInfo(form).then((response) => {
          this.$modal.msgSuccess("新增成功");
          this.editVisible = false;
          this.getDataList();
        });
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除一企一档编号为"' + ids + '"的数据项？')
        .then(function () {
          return delInfo(ids);
        })
        .then(() => {
          this.getDataList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "enterpriseInfo/info/export",
        {
          ...this.queryParams,
        },
        `info_${new Date().getTime()}.xlsx`
      );
    },
    handleTest(row) {
      // alert("待做")
    },
    
  },
};
</script>
